﻿using System;
using System.Collections.Generic;
using System.Linq;
using Capa_Entidad;
namespace Acceso_Datos.Clases_DAO
{
    public class clsAdmCitaDao
    {
        private BDClinicaEntities ContextoDeObjs = new BDClinicaEntities();
        public bool Insertar(ADM_CITA Obj)
        {
	        try 
            {
                ContextoDeObjs.AddObject("ADM_CITA", Obj);
                ContextoDeObjs.SaveChanges();
	        } 
            catch (Exception)
            {
		        return false;
	        }
	        return true;
        }
        public bool Modificar(ADM_CITA obj)
        {

            try
            {
                ContextoDeObjs.AttachTo("ADM_CITA", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception )
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(ADM_CITA obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("ADM_CITA", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public List<ADM_CITA> listar()
        {
	        List<ADM_CITA> lista = new List<ADM_CITA>();
            var q = from c in ContextoDeObjs.ADM_CITA
                    select c;
	        lista = q.ToList();
	        return lista;
        }
        public List<V_Adm_Cita> listarVista()
        {
            List<V_Adm_Cita> lista = new List<V_Adm_Cita>();
            var q = from c in ContextoDeObjs.V_Adm_Cita
                    select c;
            lista = q.ToList();
            return lista;
        }
        public List<V_Horario_Cita> listarHorario()
        {
            List<V_Horario_Cita> lista = new List<V_Horario_Cita>();
            var q = from c in ContextoDeObjs.V_Horario_Cita
                    select c;
            lista = q.ToList();
            return lista;
        }

        public int UltimoNumero()
        {
            var max = 0;

            try
            {
                 max = ContextoDeObjs.ADM_CITA.Select(x => x.CIT_ID_CITA).Max();
                return max;
            }
            catch (Exception )
            {
                return max;
            }
           

        }


    }
}
